<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>表单元素</title>
</head>
<body>
    <div id="root"></div>

    <script src="../js/react.development.js"></script>
    <script src="../js/react-dom.development.js"></script>
    <script src="../js/babel.min.js"></script>

    <script type="text/babel">
        class App extends React.Component{
            render(){
                return <div className="container">
                        <h2>登录</h2>
                        <form action="">
                            用户名: <input ref={el => this.user = el} type="text"  /> <br/>
                            密码: <input  ref={el => this.pass = el}  type="text"  /> <br/>
                            <button onClick={this.login}>登录</button>
                        </form>
                    </div>
            }

            login = (e) => {
                //阻止默认行为
                e.preventDefault();
                //获取用户名    
                let username = this.user.value;
                //获取密码
                let password = this.pass.value;

                console.log('用户名为: '+ username);
                console.log('密码为: '+ password);
            }
        }

        ReactDOM.render(<App />, document.querySelector("#root"));
    </script>
</body>
</html>